
#include "chooselevelscene.h"
#include<QMenuBar>
#include<QPainter>
#include<QPushButton>
#include<QPalette>
#include<QLabel>

ChooseLevelScene::ChooseLevelScene(QWidget *parent)
    : QMainWindow{parent}
{

    //配置选择关卡场景
    this->setFixedSize(340,560);
    //设置图标
    this->setWindowIcon(QIcon(":/picture/level.jpeg"));
    //设置标题
    this->setWindowTitle("选择关卡场景");
    //创建菜单栏
    QMenuBar* bar=menuBar();
    setMenuBar(bar);
    QMenu*startMenu=bar->addMenu("开始");
    QAction*quitAction=startMenu->addAction("退出");
    connect(quitAction,&QAction::triggered,[=](){
        this->close();
    });
    QAction*quitAction1=startMenu->addAction("返回");
    connect(quitAction1,&QAction::triggered,[=](){
        emit this->chooseSceneBack();
    });
    //创建选择关卡的按钮
    for(int i=0;i<20;i++)
    {
        QPushButton* btn3=new QPushButton(this);
        btn3->move(i%4*70+45,i/4*70+150);
        btn3->setFixedSize(40,30);
        QPalette palette2;
        palette2.setColor(QPalette::Button,QColor(48,128,30));
        btn3->setAutoFillBackground(true);
        btn3->setPalette(palette2);
        btn3->setFlat(true);
        //监听每个按钮的点击事件
        connect(btn3,&QPushButton::clicked,[=](){
            //进入到游戏场景
            this->hide();
            play=new PlayScene(i+1);
            play->show();

            connect(play,&PlayScene::chooseSceneBack,[=](){
                this->show();
                delete play;
                play=NULL;
            });
        });
        QLabel*label=new QLabel;
        label->setParent(this);
        label->setFixedSize(btn3->width(),btn3->height());
        label->setText(QString::number(i+1));
        label->move(i%4*70+60,i/4*70+150);
        label->setAttribute(Qt::WA_TransparentForMouseEvents);


    }

}
void ChooseLevelScene::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/a/background3/pure_background.jpeg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}